﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ObjectFeatures;
using System.Windows.Media.Animation;
using System.Diagnostics;

namespace WpfAlarmTimer
{
    /// <summary>
    /// Interaction logic for AlarmControl.xaml
    /// </summary>
    public partial class AlarmControl : UserControl
    {
        private Alarm _alarm;

        public AlarmControl()
        {
            InitializeComponent();
            NameScope.SetNameScope(this, new NameScope());
            this.RegisterName("animated_bg", this.mainGrid.Background);

            ColorAnimation redishAnimation = new ColorAnimation(Color.FromArgb(128, 0, 0, 0), Color.FromArgb(128, 128, 0, 0), new Duration(TimeSpan.FromSeconds(0.3)));
            redishStoryBoard.Children.Add(redishAnimation);
            Storyboard.SetTargetName(redishAnimation, "animated_bg");
            Storyboard.SetTargetProperty(redishAnimation, new PropertyPath(SolidColorBrush.ColorProperty));

            ColorAnimation unredishAnimation = new ColorAnimation(Color.FromArgb(128, 128, 0, 0), Color.FromArgb(128, 0, 0, 0), new Duration(TimeSpan.FromSeconds(0.3)));
            unredishStoryBoard.Children.Add(unredishAnimation);
            Storyboard.SetTargetName(unredishAnimation, "animated_bg");
            Storyboard.SetTargetProperty(unredishAnimation, new PropertyPath(SolidColorBrush.ColorProperty));
            
        }
        private Storyboard redishStoryBoard = new Storyboard();
        private Storyboard unredishStoryBoard = new Storyboard();

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            redishStoryBoard.Begin(this);
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            unredishStoryBoard.Begin(this);
        }

        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            this._alarm = (Alarm)e.NewValue;
            this.alarmTextBlock.Text = this._alarm.RingTime.ToString("dd/MM/yyyy'\n'HH:mm:ss");
        }

        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Here will come the edit/delete functionnality");
            //TODO display dialog to edit/remove alarm
        }
    }
}
